package com.neusoft.yuejian_01.model;


import com.neusoft.yuejian_01.base.BaseModel;
import com.neusoft.yuejian_01.javabean.IsMatchReg;
import com.neusoft.yuejian_01.javabean.MatchBean;
import com.neusoft.yuejian_01.javabean.MatchRegBean;
import com.neusoft.yuejian_01.javabean.NoRegBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.service.MatchService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/10/2.
 */

public class MatchModel extends BaseModel {
    //比赛列表
    public  void matchlist(final RetrofitListener listener){
        this.flag = Const.MatchList;
        MatchService matchService = retrofit.create(MatchService.class);
        Call<List<MatchBean>> call = matchService.getMatchlist();
        Callback<List<MatchBean>> callback = new Callback<List<MatchBean>>() {
            @Override
            public void onResponse(Call<List<MatchBean>> call, Response<List<MatchBean>> response) {
                List<MatchBean> matchBean = response.body();
                listener.onSuccess(matchBean,flag);
            }
            @Override
            public void onFailure(Call<List<MatchBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //比赛详情
    public  void matchDetail(String m_id,final RetrofitListener listener){
        this.flag = Const.MatchDetail;
        MatchService matchService = retrofit.create(MatchService.class);
        Call call = matchService.getMatchDetail(m_id);

        call.enqueue(new Callback<MatchBean>() {
            @Override
            public void onResponse(Call<MatchBean> call, Response<MatchBean> response) {
                MatchBean matchDetail=response.body();
                listener.onSuccess(matchDetail,flag);
            }

            @Override
            public void onFailure(Call<MatchBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //判断报名
    public void getIsReg(String u_id, String m_id,final RetrofitListener listener) {
        this.flag = Const.IsMatchReg;
        MatchService matchService = retrofit.create(MatchService.class);
        Call call = matchService.getIsReg(u_id,m_id);
        call.enqueue(new Callback<IsMatchReg>() {
            @Override
            public void onResponse(Call<IsMatchReg> call, Response<IsMatchReg> response) {
                IsMatchReg isMatchReg=response.body();
                listener.onSuccess(isMatchReg,flag);
            }
            @Override
            public void onFailure(Call<IsMatchReg> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //取消报名
    public void getIsNotReg(String u_id, String m_id,final RetrofitListener listener) {
        this.flag = Const.NoReg;
        MatchService matchService = retrofit.create(MatchService.class);
        Call call = matchService.getIsNotReg(u_id,m_id);
        call.enqueue(new Callback<NoRegBean>() {
            @Override
            public void onResponse(Call<NoRegBean> call, Response<NoRegBean> response) {
                NoRegBean noRegBean=response.body();
                listener.onSuccess(noRegBean,flag);
            }
            @Override
            public void onFailure(Call<NoRegBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //比赛报名订单
    public void getMatchRegistration(String u_id,String m_id,final RetrofitListener listener){
        this.flag = Const.MatchOrder;
        MatchService matchService = retrofit.create(MatchService.class);
        Call call = matchService.getMatchRegistration(u_id,m_id);
        call.enqueue(new Callback<MatchRegBean>() {
            @Override
            public void onResponse(Call<MatchRegBean> call, Response<MatchRegBean> response) {
                MatchRegBean matchRegBean=response.body();
                listener.onSuccess(matchRegBean,flag);
            }
            @Override
            public void onFailure(Call<MatchRegBean> call, Throwable t)  {
                listener.onFail();
            }
        });
    }
    //比赛报名
    public void matchreg(String u_id,String m_id,final RetrofitListener listener){
        this.flag = Const.MatchReg;
        MatchService matchService = retrofit.create(MatchService.class);
        Call call = matchService.addMatchRegistration(u_id,m_id);
        call.enqueue(new Callback<MatchRegBean>() {
            @Override
            public void onResponse(Call<MatchRegBean> call, Response<MatchRegBean> response) {
                MatchRegBean matchRegBean=response.body();
                listener.onSuccess(matchRegBean,flag);
            }
            @Override
            public void onFailure(Call<MatchRegBean> call, Throwable t)  {
                listener.onFail();
            }
        });
    }
}
